local physicsModule = require("physics")
physicsModule.start()

local ground

local function createBlock()
	local obj = display.newImage( "bottomHalf.png" )
	obj.y = display.contentHeight - 100
	physicsModule.addBody( obj, { density=3.0, friction=0.1, bounce=0.7 } )
	obj.gravityScale = 0.7
	obj:applyForce( 600, -600, obj.x, obj.y )
	return obj
end

local function createButtonFor100block()
	-- Create buttons : from SampleCode - Graphics:MovieClip
	local widget = require( "widget" )
	local onEvent = function( event )
		if ( "press" == event.phase ) then
			for i = 1, 100 do
				createBlock()
			end
		end
	end
	local throwButton = widget.newButton{
		onEvent = onEvent,
		id = "Throw",
		label = "Create Block x 100",
		fontSize = 12
	}
end


local function setUp()
	createButtonFor100block()

	createBlock()

	ground = display.newImage( "bottom.png" )
	ground.y = display.contentHeight - ( ground.height / 2 )
	physicsModule.addBody( ground, "static", { density=3.0, friction=0.1, bounce=0.5 } )
end

function main()
	setUp()
end

main()
